#include <iostream>
#include <string>
#include <iterator>
#include <fstream>
#include <algorithm>
#include <qfl/iterator.hpp>
#include <qfl/text/utf.hpp>
//#include "filter.h"
//#include <boost//iostreams/filtering_stream.hpp>


int main()
{
	std::ifstream in("test.txt");

	qfl::text::utf_bom bom=qfl::text::get_utf_bom(in);
/*
	namespace io = boost::iostreams;

	io::filtering_istream fin;
	fin.push(utf::utf8_input_filter());   
	fin.push(std::istream_iterator<char>(in));

*/
	typedef qfl::istream_filter_iterator<wchar_t> wchar_istream_iterator;
	wchar_istream_iterator it_beg(in,qfl::text::fun_get_char(bom));
	wchar_istream_iterator it_end;
	std::wstring str(it_beg,it_end);
	//std::copy(it_beg,it_end,std::back_insert_iterator<wchar_t>(str));
	std::wcout.imbue(std::locale("chs"));
	std::wcout<<str;
/*
	std::wcout<<sizeof(qfl::utf::utf8_char);
	
	qfl::text::utf8_istream_iterator it_beg(in);
	qfl::text::utf8_istream_iterator it_end;
	std::wstring str(it_beg,it_end);

	std::wcout.imbue(std::locale("chs"));
	std::wcout<<str;
*/

	std::ofstream out("test.out.txt");
	
	qfl::text::put_utf_bom(out,bom);
	std::for_each(str.begin(),str.end(),
		std::tr1::bind(
			qfl::text::fun_put_char(bom),
			std::tr1::ref(out),
			std::tr1::placeholders::_1));

	return 0;
}



/*
#include <qfl/iterator/istream_filter_iterator.hpp>

char plus1(std::istream& in)
{
	return in.get()+1;
}
int main()
{
	typedef qfl::iterator::istream_wrapper_iterator<char> my_it;
	my_it beg(std::cin,std::ptr_fun(plus1)),end;

	std::string str(beg,end);

	std::cout<<str;

	return 0;
}
*/
